/**
 * Class Animation craete css class with animatoin.
 * Example:
 * var animation = new Animation('slide-down', 100, 'slidedown', 'linear');
 */
Animation = (function () {
	/**
	 *
	 * @param name {String} Css Class name
	 * @param time {Number} Animation time in ms
	 * @param [animationName] {String} Animation Name
	 * @param [timeFunction] {String} Animation timing function linear|easing or bezier
	 * @constructor
	 */
	function Animation(name, time, animationName, timeFunction) {
		this.style = new Style();
		this.setName(name);
		this.setAnimationName(animationName);
		this.setFunction(timeFunction);
		this.setTime(time);
	}
	/**
	 * Create Css object rule
	 * @returns {Object}
	 */
	Animation.prototype.createRule = function(){
		var rule = {};
		if(this.animationName !== void 0) rule["-webkit-animation-name"] = this.animationName;
		if(this.time !== void 0) rule["-webkit-animation-duration"] = this.time+"ms";
		if(this.timeFunction !== void 0) rule["-webkit-animation-timing-function"] = this.timeFunction;
		return rule;
	};
	/**
	 * Set Animation css class name
	 * @param name {String} Css Class name
	 */
	Animation.prototype.setName = function(name){
		this.name = name;
		this.ruleIndex = this.style.addRule("."+name, this.createRule());
	};
	/**
	 * Set Animation Name
	 * @param name {String} css animation name
	 */
	Animation.prototype.setAnimationName = function(name){
		this.animationName = name;
		this.style.editRule(this.ruleIndex, this.createRule());
	};
	/**
	 * Set Animation Timing Function
	 * @param [timeFunction] {String} Timing Function
	 */
	Animation.prototype.setFunction = function(timeFunction){
		this.timeFunction = timeFunction || "linear";
		this.style.editRule(this.ruleIndex, this.createRule());
	};
	/**
	 * Set Animation Time in ms
	 * @param time {Number} Animation Time
	 */
	Animation.prototype.setTime = function(time){
		this.time = time;
		this.style.editRule(this.ruleIndex, this.createRule());
	};
	/**
	 * Remove Animation Css Rule
	 * @returns {*}
	 */
	Animation.prototype.remove = function(){
		return this.style.removeRule(this.ruleIndex);
	};

	return Animation;

})();